<template>
	<view>
		<view class="box">
			<view class="boxTitle">
				提现金额(可提现{{(data.brokeragePrice/100).
					toFixed(2)}}元)
			</view>
			<view class="boxPrice">
				<u--input placeholder="请输入金额" v-model="price" type="digit" prefixIcon="rmb"
					prefixIconStyle="font-size: 22px;color: #000" border="none" @change="change"></u--input>
			</view>
		</view>
		<view class="box">
			<view class="box2Tit">
				<view class="titlL">
					请输入姓名
				</view>
				<view class="titlR">
					<u--input placeholder="提现微信实名认证" v-model="name" type="text" inputAlign="right" border="none"
						:customStyle="{width:'100%',height:'100rpx'}"></u--input>
				</view>
			</view>
			<view class="box2ImgT">
				微信收款码
			</view>
			<image class="box2Img" :src="img ||'../../static/other/check.png'" @click="checkImg"></image>
		</view>
		<view class="but" @click="embody">
			提现
		</view>
	</view>
</template>

<script>
	import {
		uploadXpPath
	} from "@/api/merchants/merchants.js"
	import {
		createEmbody
	} from "@/api/embody/embody.js"
	import {
		getWorkInfo
	} from "@/api/work/work.js"
	export default {
		data() {
			return {
				price: '',
				name: '',
				img: '',
				maxPrice: '',
				data: {}
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			//校验金额
			change() {
				if (this.price * 100 > this.data.brokeragePrice) {
					uni.$u.toast('提现金额不可大于余额')
					this.price = ''
				}
			},
			//发起提现
			embody() {
				let that = this
				if (!that.price) {
					uni.showToast({
						title: '请输入提现金额',
						icon: 'none'
					})
					return false
				}
				if (!that.name) {
					uni.showToast({
						title: '请输入微信实名认证的姓名',
						icon: 'none'
					})
					return false
				}
				if (!that.img) {
					uni.showToast({
						title: '请上传微信收款码',
						icon: 'none'
					})
					return false
				}
				let priceBig = that.price * 100
				let data = {
					type: 3,
					price: priceBig,
					accountQrCodeUrl: that.img,
					accountNo: that.name,
					bankName: "",
					bankAddress: ""
				}
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				// console.log(data)
				// uni.$emit('emit',1)
				createEmbody(data).then(response => {
					uni.$u.toast('申请成功，请等待审核')
					that.price = ''
					that.name = ''
					that.img = ''
					uni.$emit('emit',1)
					setTimeout(() => {
						this.$tab.navigateBack(1)
					}, 1000)
				})
			},
			checkImg() {
				let that = this
				uni.chooseMedia({
					count: 1,
					mediaType: ['image'],
					sourceType: ['album', 'camera'],
					maxDuration: 30,
					camera: 'back',
					success(res) {
						let data = {
							filePath: res.tempFiles[0].tempFilePath
						}
						uni.showLoading({
							title: '加载中',
							mask: true
						})
						uploadXpPath(data).then(response => {
							uni.hideLoading()
							that.img = response.data
						})
					}
				})
			},
			//获取业务员交易信息
			getInfo() {
				let that = this
				uni.showLoading({
					title: '加载中'
				})
				getWorkInfo().then(res2 => {
					if (res2.code == 0) {
						uni.hideLoading()
						that.data = res2.data
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}

	.box {
		width: 690rpx;
		/* height: 220rpx; */
		background: #F5F5F5;
		padding-bottom: 30rpx;
		border-radius: 20rpx;
		margin: 20rpx auto 0 auto;
	}

	.boxTitle {
		width: 630rpx;
		height: 100rpx;
		line-height: 100rpx;
		margin: 0 auto;
		font-size: 24rpx;
		color: #999999;
	}

	.boxPrice {
		width: 630rpx;
		height: 80rpx;
		/* line-height: 100rpx; */
		margin: 0 auto;
		border-bottom: 2rpx solid #DEDEDE;
		;
	}

	.box2Tit {
		width: 630rpx;
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		justify-content: space-between;
		margin: 0 auto;
		font-size: 24rpx;
		color: #333333;
		align-items: center;
		border-bottom: 2rpx solid #DEDEDE;
	}

	.titlL {
		width: 200rpx;
		height: 100rpx;
	}

	.titlR {
		width: 400rpx;
		height: 100rpx;
		text-align: end;
	}

	.box2ImgT {
		width: 630rpx;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 24rpx;
		color: #333333;
		margin: 0 auto;
	}

	.box2Img {
		width: 164rpx;
		height: 136rpx;
		margin-left: 30rpx;
	}

	.but {
		width: 690rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		position: fixed;
		bottom: 120rpx;
		left: 30rpx;
		background: #E84E22;
		border-radius: 32rpx;
		font-size: 28rpx;
		color: #FFFFFF;
	}
</style>